import { userAccountLogin } from '@/api/user'
// 用户状态
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  mutations: {
    setProfile (state, profile) {
      state.profile = profile
    },
    removeProfile (state) {
      state.profile = {
        id: '',
        avatar: '',
        nickname: '',
        account: '',
        mobile: '',
        token: ''
      }
    }
  },
  actions: {
    async loginAction ({ commit }, form) {
      const { result } = await userAccountLogin(form)
      commit('setProfile', result)
      console.log(result)
    },

    logoutAction ({ commit }) {
      commit('removeProfile')
      commit('cart/setCartList', [], { root: true })
    }
  }
}
